using System;
using System.Collections.Generic;
using System.Linq;

namespace PegasCompany.Data
{
	public partial class EmailTemplate : IComparable<EmailTemplate>
	{
		private List<FileAttach> _fileAttachements;
		public List<FileAttach> FileAttachements
		{
			get
			{
				_fileAttachements = new List<FileAttach>();
				if (TemplateId != null)
					_fileAttachements.AddRange(FileAttach.ListByTemplateId(TemplateId.Value));

				return _fileAttachements;
			}
		}

		public void Save()
		{
			CreateDate = DateTime.Now;
			LastModifiedDate = DateTime.Now;

			Insert();
		}

		public void UpdateInstance()
		{
			LastModifiedDate = DateTime.Now;

			Update();
		}

		public void MarkAsDeleted()
		{
			throw new NotImplementedException();
		}

		public static List<EmailTemplate> GetAllEmailTemplates()
		{
			return Search();
		}

		public static EmailTemplate GetEmailTemlateByType(int emailTemplateType)
		{
			return Search(new EmailTemplate
			              	{
			              		TemplateType = emailTemplateType
			              	}).FirstOrDefault();
		}

		public int CompareTo(EmailTemplate other)
		{
			return Subject.CompareTo(other.Subject);
		}
	}
}

